<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/10/18
 * Time: 17:03
 */

namespace app\index\controller;
use think\Db;
use think\Response;
use think\Request;
class Config
{

    public function area_phone($area_name){
        $data = Db::name('area')->where('area_name','like','%'.$area_name.'%')->value('area_name');
        if($data){

        }
    }

    public function fuwuxieyi()
    {
        $data = Db::name('about')->where('id', 9)->value('content');
        $content  = '<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">';
        $content .= '<style> img {vertical-align:middle; width:auto; max-width:95%;} </style>';
        $content .= $data;
        return Response::create($content, 'html');
    }
    public function yinsizhengce()
    {
        $data = Db::name('about')->where('id', 2)->value('content');
        $content  = '<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">';
        $content .= '<style> img {vertical-align:middle; width:auto; max-width:95%;} </style>';
        $content .= $data;
        return Response::create($content, 'html');
    }

    public function about_us()
    {
        $data = Db::name('about')->where('id', 1)->value('content');
        $content  = '<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">';
        $content .= '<style> img {vertical-align:middle; width:auto; max-width:95%;} </style>';
        $content .= $data;
        return Response::create($content, 'html');
    }
    public function reg()
    {
        $data = Db::name('about')->where('id', 2)->value('content');
        $content  = '<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">';
        $content .= '<style> img {vertical-align:middle; width:auto; max-width:95%;} </style>';
        $content .= $data;
        return Response::create($content, 'html');
    }
    public function coupon()
    {
        $data = Db::name('about')->where('id', 8)->value('content');
        $content  = '<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">';
        $content .= '<style> img {vertical-align:middle; width:auto; max-width:95%;} </style>';
        $content .= $data;
        return Response::create($content, 'html');
    }

    public function hide()
    {
        $data = Db::name('about')->where('id', 3)->value('content');
        $content  = '<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">';
        $content .= '<style> img {vertical-align:middle; width:auto; max-width:95%;} </style>';
        $content .= $data;
        return Response::create($content, 'html');
    }

    public function question()
    {
        $data = Db::name('about')->where('id', 4)->value('content');
        $content  = '<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">';
        $content .= '<style> img {vertical-align:middle; width:auto; max-width:95%;} </style>';
        $content .= $data;
        return Response::create($content, 'html');
    }

    public function active()
    {
        $data = Db::name('about')->where('id', 5)->value('content');
        $content  = '<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">';
        $content .= '<style> img {vertical-align:middle; width:auto; max-width:95%;} </style>';
        $content .= $data;
        return Response::create($content, 'html');
    }
    public function avtive()
    {
        $data = Db::name('about')->where('id', 5)->value('content');
        $content  = '<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">';
        $content .= '<style> img {vertical-align:middle; width:auto; max-width:95%;} </style>';
        $content .= $data;
        return Response::create($content, 'html');
    }
    public function draw()
    {
        $data = Db::name('about')->where('id', 6)->value('content');
        $content  = '<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">';
        $content .= '<style> img {vertical-align:middle; width:auto; max-width:95%;} </style>';
        $content .= $data;
        return Response::create($content, 'html');
    }

    public function others()
    {
        $data = Db::name('about')->where('id', 100)->value('content');
        $content  = '<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">';
        $content .= '<style> img {vertical-align:middle; width:auto; max-width:95%;} </style>';
        $content .= $data;
        return Response::create($content, 'html');
    }
    public function other()
    {
        $data = Db::name('about')->where('id', 100)->value('content');
        $content  = '<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">';
        $content .= '<style> img {vertical-align:middle; width:auto; max-width:95%;} </style>';
        $content .= $data;
        return Response::create($content, 'html');
    }

    public function platform_tel(){
        $data = Db::name('config')->where('varname','in','web_service_tel,web_report_tel')->column('varvalue');
        return ['code' => 200 ,'message' => '服务电话和监督电话','service_tel' => $data[0],'report_tel' => $data[1]];
    }

    public function car_help_phone($city_name = ''){
        $data = Db::name('config')->where('varname','in','web_car_help_phone')->value('varvalue');
        return ['code' => 200 ,'message' => '汽车救援电话','phone' => $data,];
    }

    public function gift_phone1(){
        $data = Db::name('config')->where('varname','in','web_service_tel,web_report_tel')->column('varvalue');
        return ['code' => 200 ,'message' => '服务电话','service_tel' => $data[0]];
    }

    public function gift_phone2(){
        $data = Db::name('config')->where('varname','in','web_service_tel,web_report_tel')->column('varvalue');
        return ['code' => 200 ,'message' => '服务电话','service_tel' => $data[0]];
    }

    public function hot_search(){
        $data = Db::name('config')->where('varname','in','web_hot_search')->value('varvalue');
        return ['code' => 200 ,'message' => '热门搜索','data' => explode(',',$data)];
    }

    function enquiry(){
            $data = Db::name('config')->where('varname','in','web_hot_search')->value('varvalue');
            return ['code' => 200 ,'message' => '违章查询','data' => explode(',',$data)];
    }

    function is_show(){
        $data = Db::name('config')->where('varname','in','web_is_show')->value('varvalue');
        return ['code' => 200 ,'message' => '实名认证隐藏项Y隐藏N显示','data' => $data];
    }


    /**
     * 检查更新(安卓)
     */
    public function check_update()
    {

        $data = Request::instance()->param('versions');

        $versions = (int)Db::name('Config')->where('varname', 'web_android_version')->value('varvalue');

        $url = "https://www.pgyer.com/NcF9";
        //是否强制更新
        // if ($versions['force'] == 0) {

        if ($data == $versions) {
            return ['code' => 403, 'message' => '无需更新'];
        } else {
            return ['code' => 200, 'message' => '可以更新', 'url' => $url];
        }
        // } else {
        //     return ['code' => 200, 'message' => '强制更新', 'url' => $url];
        // }


    }


    public function ios_update()
    {
        $data = Request::instance()->param('versions');

        $versions = (float)Db::name('Config')->where('varname', 'web_ios_version')->value('varvalue');

        $url = "https://www.pgyer.com/7pjm";
        //是否强制更新
        // if ($versions['force'] == 0) {

        if ($data == $versions) {
            return ['code' => 403, 'message' => '无需更新','versions' => $versions];
        } else {
            return ['code' => 200, 'message' => '可以更新', 'url' => $url, 'versions' => $versions];
        }
        // } else {
        //     return ['code' => 200, 'message' => '强制更新', 'url' => $url];
        // }
    }

    public function help($parent_id = 0){
        $data = Db::name('single1')->where('parent_id',$parent_id)
            ->where('is_delete',1)
            ->field('id,cat_name')
            ->order('id','asc')
            ->select();
        if($parent_id != 0){
            $data = Db::name('single1')->where('parent_id',$parent_id)
                ->where('is_delete',1)
                ->field('id,cat_name,sort url')
                ->order('id','asc')
                ->select()->toArray();
            foreach ($data as $k => &$v){
                $v['url'] = 'http://lihai.xmdonkey.com/index.php/index/config/help_view/id/'.$v['id'];
            }
        }
        return ['code' => 200 ,'message' => '帮助栏目类','data' => $data];
    }

    public function help_view($id){
        $data = Db::name('single1')->where('id', $id)->value('content');
        $content  = '<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">';
        $content .= '<style> img {vertical-align:middle; width:auto; max-width:95%;} </style>';
        $content .= $data;
        return Response::create($content, 'html');
    }
}